/*
 * Copyright (c) 2009 Nathaniel Houghton <nathan@brainwerk.org>
 *                    Robert Kirchgessner <rkirchge@gmail.com>
 *
 * Permission to use, copy, modify, and distribute this software for
 * any purpose with or without fee is hereby granted, provided that
 * the above copyright notice and this permission notice appear in all
 * copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
 * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 *
 */
 
#ifndef MODE_H
#define MODE_H

#include "cmd.h"
 
#define MODE_ELM 0
#define MODE_LOG 1
#define MODE_CONFIG 2
 
#define STATE_0_INIT 0x00
#define STATE_FF_END 0xFF

extern char *mode_str[];

struct mode {
	uint8_t mode;
	uint8_t state;

	uint8_t new_mode;
	uint8_t mode_update;

	uint8_t new_state;
	uint8_t state_update;
}; 

uint8_t change_mode(struct mode *mode, uint8_t newmode);
void change_state(struct mode *mode, uint8_t newstate);
void mode_seq(struct mode *);
void mode_handle(struct mode *);
uint8_t ser_mode_change(struct mode *, struct cmd *);
uint8_t ui_mode_change(struct mode *);
 
void elm_mode(struct mode *);
void config_mode(struct mode *);
void log_mode(struct mode *);
 
#endif
